<!--
 * @FilePath: 01累加器.html
 * @Author: 苏苏少年
 * @Date: 2022-11-25 18:49:07
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var sum = 0;
        // // 计算 1+2+3....+100 的和
        // // i就是每一项的值
        // for(var i = 1; i<=100; i++){
        //     sum+=i;
        //     // sum = sum + i;
        // }
        // alert(sum);
        
        var sum = 0;
        var n = Number(prompt("请输入你的数字n:"));
        for(var i = 0; i<n; i++){
            var item = (i+2+1)/(i+2);
            sum += item;
        }
        alert("计算结果为:"+ sum.toFixed(2));
    </script>
</body>
</html>